﻿using System.Collections.ObjectModel;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApp3CollectionBinding;

/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
    //private readonly List<Person> _people;
    private readonly ObservableCollection<Person> _people;

    public MainWindow()
    {
        InitializeComponent();
        _people = new ObservableCollection<Person>{
            new Person("Bart", 10),
            new Person("Homer", 45),
            new Person("Marge", 35),
            new Person("Lisa", 12),
            new Person("Maggie", 1)
        };
        _list.ItemsSource = _people;
        _comboBox.DataContext = _people;
    }

    private void OnAdd(object sender, RoutedEventArgs e)
    {
        _people.Add(new Person("Moe", 40));
    }
}
record Person(string Name, int Age)
{
    public override string ToString()
    {
        return string.Format("{0} is {1} years old", Name, Age);
    }
}
